package co.baiku.boot.common.validate;

import co.baiku.boot.common.tools.ObjectTools;

import java.util.ArrayList;
import java.util.List;

public class ValidationResults {
    private List<ValidationResult> validationResults = new ArrayList<>();

    public void add(ValidationResult validationResult) {
        validationResults.add(validationResult);
    }

    public ValidationResult first() {
        return validationResults.isEmpty() ? new ValidationResult(true, "") : validationResults.get(0);
    }

    public void clear() {
        validationResults.clear();
    }

    public boolean isSuccess() {
        return getErrorCount() == 0;
    }

    public int getErrorCount() {
        return ObjectTools.isBlank(validationResults) ? 0 : validationResults.size();
    }


    public List<ValidationResult> getValidationResults() {
        return validationResults;
    }

    public void setValidationResults(List<ValidationResult> validationResults) {
        this.validationResults = validationResults;
    }
}
